from django.db import models


# Create your models here.
class User(models.Model):
    # id = models.AutoField(primary_key=True) # 不写主键，会默认生成一个名为id的自增长的主键
    name = models.CharField(max_length=100)
    age = models.IntegerField()
    sex = models.IntegerField()
    address = models.TextField()
    phone = models.CharField(max_length=20)
    deleted = models.BooleanField(default=False)
    status = models.SmallIntegerField(default=1)
    create_time = models.DateTimeField(auto_now_add=True)
    update_time = models.DateTimeField(auto_now=True)

    class Meta:
        # db_table = 'user'  # 指定表名称
        ordering = ['update_time']  # 查询数据按照时间排序

    def __str__(self):
        return f"name:{self.name},age:{self.age},sex:{'男' if self.sex == 1 else '女'},address:{self.address},phone:{self.phone}"


class Author(models.Model):
    title = models.CharField(max_length=100, null=True)
    content = models.TextField(null=True)
    author = models.ForeignKey(User, on_delete=models.CASCADE, null=True)
    is_active = models.BooleanField(default=True)
    username = models.CharField(max_length=100)
    date_joined = models.DateTimeField(auto_now_add=True)
    date_updated = models.DateTimeField(auto_now=True)
    email = models.EmailField()
    visit_count = models.IntegerField(default=0)
    desc = models.TextField()
    website = models.URLField()
